/**
 * Copyright (C), 2015-2019, bogewang
 * FileName: LoginTokenMapper
 * Author:   foren236598164@aliyun.com
 * Date:     2019/9/16 14:32
 * Description: 登录token
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bogewang.member.mapper;

import com.bogewang.member.entity.LoginDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 〈登录token〉
 *
 * @author foren236598164@aliyun.com
 * @create 2019/9/16
 * @since 1.0.0
 */
public interface LoginTokenMapper {

    /**
     * 根据userid+loginType +is_availability=1 进行查询
     *
     * @param userId
     * @param loginType
     * @return
     */
    @Select("SELECT id ,token ,loginType, deviceInfo ,isAvailable ,userId, createTime,updateTime FROM meite_user_token WHERE " +
            "userid=#{userId} AND logintype=#{loginType} and isAvailable ='1'")
    LoginDTO selectByUserIdAndLoginType(@Param("userId") Long userId, @Param("loginType") String loginType);

    /**
     * 根据userId+loginType token的状态修改为不可用
     *
     * @param userId
     * @param loginType
     * @return
     */
    @Update(" update meite_user_token set isAvailable  ='0', updatetime=now() where token=#{token}")
    int updateTokenAvailable(@Param("token") String token);

    /**
     * token记录表中插入一条记录
     *
     * @param userTokenDo
     * @return
     */
    @Insert(" INSERT INTO `meite_user_token` VALUES (null, #{token},#{loginType}, #{deviceInfo}, 1, #{userId} ,now(), null )")
    int insertUserToken(LoginDTO loginDTO);
}